﻿var gulp = require('gulp');

var concat = require('gulp-concat');/*合并文件*/

var cleanCSS = require('gulp-clean-css');/*压缩css*/

var uglify = require('gulp-uglify');/*压缩js*/

var rename = require("gulp-rename");/*重命名*/

var imagemin = require('gulp-imagemin');/*图片压缩*/

var tinypng = require('gulp-tinypng-compress');

var pump = require('pump');

gulp.task('c-css', function() {
    return gulp.src('dev/css/*.css')
        .pipe(concat('all.css'))
        .pipe(gulp.dest('src/css/'));
});

gulp.task('c-js', function() {
    return gulp.src('dev/js/*.js')
        .pipe(concat('all.js'))
        .pipe(gulp.dest('src/js/'));
});

gulp.task('m-css', function() {
    return gulp.src('src/css/*.css')
        .pipe(cleanCSS())
        .pipe(rename({
            suffix: ".min"
        }))
        .pipe(gulp.dest('src/css/'));
});

gulp.task('m-js', function(cb) {
    pump([
        gulp.src('src/js/*.js'),
        uglify(),
        rename({
            suffix: ".min"
        }),
        gulp.dest('src/js/')
    ],cb);
});

gulp.task('m-img', function() {
    return gulp.src('dev/images/*')
        .pipe(imagemin({
            progressive: true
        }))
        .pipe(gulp.dest('src/images/'));
});

gulp.task('m-tin', function () {
    return gulp.src('dev/images/*.{png,jpg,jpeg}')
        .pipe(tinypng({
            key: '8_wvfTCmEEc8blHwGQevF9XyYTmQ3dRi',
            log: true
        }))
        .pipe(gulp.dest('src/images/'));
});